package com.aso114.project.mvp.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.aso114.project.R;
import com.aso114.project.adapter.OrderAdapter;
import com.aso114.project.adapter.SelectedTopicPayAdapter;
import com.aso114.project.base.BaseSimpleActivity;
import com.aso114.project.bean.OrderBean;
import com.aso114.project.dialog.PayDialog;
import com.aso114.project.mvp.model.CallBack;
import com.aso114.project.mvp.model.CommentModel;
import com.aso114.project.util.Constant;
import com.aso114.project.util.Helper;
import com.aso114.project.util.SpaceItemDecoration;
import com.aso114.project.util.SpfUtil;
import com.aso114.project.util.ToastUtils;

import java.io.Serializable;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MyOrderActivity extends BaseSimpleActivity {
    @BindView(R.id.layout_title_bar_back_iv)
    ImageView layoutTitleBarBackIv;
    @BindView(R.id.layout_title_bar_title_tv)
    TextView layoutTitleBarTitleTv;
    @BindView(R.id.layout_title_bar_right_iv)
    ImageView layoutTitleBarRightIv;
    @BindView(R.id.layout_title_bar_right_tv)
    TextView layoutTitleBarRightTv;
    @BindView(R.id.title_top_ly)
    RelativeLayout titleTopLy;
    @BindView(R.id.order_listView)
    RecyclerView orderListView;
    OrderAdapter adapter;
    @Override
    protected int getResouseId() {
        return R.layout.activity_myorder;
    }

    @Override
    protected void initView() {




        layoutTitleBarTitleTv.setText("我的订单");
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        //设置布局管理器
        orderListView.setLayoutManager(layoutManager);
        orderListView.addItemDecoration(new SpaceItemDecoration(20));
        getData();
    }

    public void getData( ) {
        CommentModel.getInstant().get_oder_list( new CallBack() {
            @Override
            public void onSuccess(Object o, boolean isSuccess, String msg) {
                Helper.gotoLogin(isSuccess);//token失效去重新登陆

                List<OrderBean> Data = (List<OrderBean>) o;
                adapter = new OrderAdapter(MyOrderActivity.this,Data);
                orderListView.setAdapter(adapter);
                adapter.notifyDataSetChanged();


                adapter.setOnItemClickListener(new OrderAdapter.OnItemClickListener() {
                    @Override
                    public void onClick(int position,View v) {
                        orderListView.scrollToPosition(position);
                        adapter.notifyDataSetChanged();
                    }
                });
            }

            @Override
            public void onFailure(String fail) {

            }

        });


    }


    @Override
    protected void initData() {

    }

    @Override
    protected void getBroadcast(Context context, Intent intent) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick(R.id.layout_title_bar_back_iv)
    public void onViewClicked() {
        finish();
    }
}
